home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / phigs / ptk.lha / ptk / source / demo / stcttest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  6.6 KB  |  260 lines

  1. /*--------------------------------------------------------------------------- 
  2.  
  3.  Program name: Structure Content Drawer demo program.
  4.  
  5.  Author: Gareth Williams
  6.  
  7.  Description: Demonstrates the structure content drawer module.
  8.  
  9.  Modification history : (Version), (Date), (Name), (Description).
  10.  
  11.  1.0, 1st July 1991, G. Williams, First Version.
  12.  
  13.  2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
  14.  
  15.  SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
  16.  
  17. ----------------------------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <math.h>
  21. #include <phigs.h>
  22. #include "ptk.h"
  23.  
  24. #define WS1 1
  25.  
  26. /* Operating system dependent code, UNIX/VMS pathnames */
  27. /* UNIX pathnames */
  28. #define SCRIPTNAME "../scripts/postcard.scr"
  29. #define OPENWSNAME "../scripts/openws.scr"
  30.  
  31. /*
  32. #ifdef VMS
  33. #define SCRIPTNAME "[-.scripts]postcard.scr"
  34. #endif
  35. */
  36.  
  37. static char *colwrd[] = 
  38.      {
  39.          "BLACK", "WHITE", "GREEN", 
  40.          "BLUE", "CYAN", "GREY", "RED" 
  41.      };
  42.  
  43. static Pfloat devx, devy, devz;
  44. static Pint textfont, white, black, green, grey, blue;
  45. static ptkboolean docolour = FALSE;
  46.  
  47. /*--------------------------------------------------------------------------*/
  48.  
  49. static void set_attrs()
  50. {
  51.   if (docolour)
  52.   {
  53.     pset_text_colr_ind(black);
  54.     pset_edge_flag(PEDGE_ON);
  55.     pset_int_style(PSTYLE_SOLID);
  56.     pset_edge_colr_ind(white);
  57.     pset_int_colr_ind(green);
  58.   }
  59. }  /* set_attrs */
  60.  
  61. /*--------------------------------------------------------------------------*/
  62.  
  63. static void options(C(void))
  64. {
  65.   char commandstr[20], writestr[50];
  66.   Pint lencom, lenstr, err, elem1, elem2, eptr, postcardid;
  67.   ptkboolean structquit;
  68.   Plimit echoarea;
  69.  
  70.   structquit = FALSE;
  71.   eptr = 0;
  72.   postcardid = ptk_stringtoint("structureid", "postcard");
  73.   do
  74.   {
  75.     echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
  76.     ptk_readstring(WS1, "range", "Input command (default = range) >", 
  77.                    &echoarea, 20, commandstr, &lencom);
  78.     if (strncmp(commandstr, "range", lencom) == 0)
  79.     {
  80.       elem1 = ptk_readint(WS1, 1, "Input element number (1) >", &echoarea);
  81.       elem2 = ptk_readint(WS1, 0, "Input element number (0) >", &echoarea);
  82.       pempty_struct(ptk_stringtoint("structureid", "content"));
  83.       popen_struct(ptk_stringtoint("structureid", "content"));
  84.       set_attrs();
  85.       ptk_structcontent(WS1, postcardid, elem1, elem2, eptr, textfont, &err);
  86.       pclose_struct();
  87.     }
  88.     else
  89.     if (strncmp(commandstr, "pointer", lencom) == 0)
  90.     {
  91.       eptr = ptk_readint(WS1, 0, "Input element pointer (0) >", &echoarea);
  92.       popen_struct(ptk_stringtoint("structureid", "content"));
  93.       ptk_setstructcontentelemptr(ptk_stringtoint("structureid", "content"), 
  94.                                   eptr);
  95.       pclose_struct();
  96.     }
  97.     else if (strncmp(commandstr, "hardcopy", lencom) == 0)
  98.     {
  99.       Pint stid, lenname;
  100.       char filename[80];
  101.  
  102.       ptk_readstring(WS1, "content", 
  103.                    "Input filename (default = content) >", &echoarea,
  104.                    80, filename, &lenname);
  105.  
  106.       /* Implementation dependent code, open a hardcopy workstation */
  107. #ifdef SUN
  108.       popen_ws(2, filename, phigs_ws_type_cgm_out);
  109.       ppost_struct(2, ptk_stringtoint("structureid", "content"), 0.0);
  110.       pupd_ws(2, PFLAG_PERFORM);
  111.       pclose_ws(2);
  112. #endif
  113.     }    
  114.     else if (strncmp(commandstr, "help", lencom) == 0)
  115.     {
  116.       printf("stcttest options\n");
  117.       printf("----------------\n");
  118.       printf("range - define element range for structure content diagram\n");
  119.       printf("pointer - set element pointer\n");
  120.       printf("hardcopy - post structure content to hardcopy workstation\n");
  121.       printf("quit - exit stcttest\n");
  122.     }    
  123.     else if (strncmp(commandstr, "quit", lencom) == 0)
  124.     {
  125.       structquit = TRUE;
  126.     }    
  127.     else
  128.     {
  129.       printf("Command unknown\n");    
  130.     }
  131.     pupd_ws(WS1, PFLAG_PERFORM);
  132.   } while (structquit == FALSE);
  133. }
  134.  
  135. /*--------------------------------------------------------------------------*/
  136.  
  137. main()
  138. {
  139.   FILE *f;
  140.   char dummystr[10];
  141.   Pint dummylen, err, minid, maxid;
  142.   Pint wst;
  143.  
  144.   printf("Demonstrating the structure draw module of the PHIGS Toolkit...\n");
  145.  
  146.   /* Implementation dependent code, open PHIGS and workstation */
  147. #ifdef SUN
  148.   printf("Opening SunPHIGS...\n");
  149.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  150.  
  151.   /* open the workstation */
  152.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  153.     
  154. /* create the workstation type (either tool or canvas) 
  155.  
  156.   wst = phigs_ws_type_create( phigs_ws_type_x_tool,
  157.     PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
  158.     0);
  159.   if ( !wst ) 
  160.   {
  161.     pclose_phigs();
  162.     exit(1);
  163.   }
  164.  
  165.   popen_ws(WS1, (void *)NULL, wst);
  166.   {
  167.     Pws_st    ws_state;
  168.     
  169.     pinq_ws_st(&ws_state);
  170.     if (ws_state != PWS_ST_WSOP)
  171.       exit(3);
  172.   }
  173. */
  174. #endif
  175. #ifdef PEXSI
  176.   printf("Opening PEX-SI PHIGS...\n");
  177.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  178.  
  179.   /* open the workstation */
  180.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  181. #endif
  182. #ifdef HP
  183.   printf("Opening HP PHIGS...\n");
  184.   popen_phigs(stderr, PDEF_MEM_SIZE);
  185.  
  186.   /* open the workstation */
  187.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  188. #endif
  189.  
  190.   ptk_inqmaxdevicecoords(WS1, &devx, &devy);
  191.   devz = 0.0;
  192.  
  193. #ifdef SUN
  194. #ifndef SUNMONO
  195.   docolour = TRUE;
  196. #endif
  197. #endif
  198. #ifdef HP
  199. #ifndef HPMONO
  200.   docolour = TRUE;
  201. #endif
  202. #endif
  203. #ifdef PEXSI
  204. #ifndef PEXSIMONO
  205.   docolour = TRUE;
  206. #endif
  207. #endif
  208.  
  209.   pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
  210.   minid = 1;
  211.   maxid = 30;
  212.   ptk_inithashtables();
  213.   ptk_createhashtable("structureid", minid, maxid);
  214.   ptk_createhashtable("label", 0, maxid);
  215.   ptk_createhashtable("colourindex", 1, 8);
  216.  
  217.    /* set colours */
  218.    if (docolour)
  219.    {
  220.      ptk_setupcolourtable(WS1, 7, colwrd);
  221.      green = ptk_stringtoint("colourindex", "green");
  222.      grey = ptk_stringtoint("colourindex", "grey");
  223.      white = ptk_stringtoint("colourindex", "white");
  224.      black = ptk_stringtoint("colourindex", "black");
  225.      blue = ptk_stringtoint("colourindex", "blue");
  226.    
  227.      /* Implementation dependent code, choose a nice font */
  228. #ifdef SUN
  229.      textfont = PFONT_TRIPLEX;
  230. #endif
  231. #ifndef SUN
  232.      textfont = 1;
  233. #endif
  234.      ptk_setbackgroundcolourind(WS1, grey);
  235.   }
  236.  
  237.   if (ptk_readphinterscript(SCRIPTNAME, NULL, NULL))
  238.   {
  239.     popen_struct(ptk_stringtoint("structureid", "content"));
  240.     set_attrs();
  241.     ptk_structcontent(WS1, ptk_stringtoint("structureid", "postcard"), 
  242.                       1, 0, 0, textfont, &err);
  243.     pclose_struct();
  244.  
  245.     if (err == 0)
  246.       ppost_struct(WS1, ptk_stringtoint("structureid", "content"), 0.0);
  247.  
  248.     pupd_ws(WS1, PFLAG_PERFORM);
  249.     options();
  250.   }
  251.  
  252.   pclose_ws(1);
  253.   pclose_phigs();
  254.   exit(0);
  255. }
  256.  
  257. /*--------------------------------------------------------------------------*/
  258.  
  259. /* end of stcttest.c */
  260.